]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
screenshot: Allow saving to clipboard
authorCarlos Garnacho <carlosg@gnome.org>
Tue, 5 Nov 2019 23:48:25 +0000 (00:48 +0100)
committerFlorian Müllner <florian.muellner@gmail.com>
Wed, 6 Nov 2019 22:45:22 +0000 (22:45 +0000)
If no target file is specified (i.e. filename is an empty string), the
screenshot will be stored on the clipboard instead.

https://gitlab.gnome.org/GNOME/mutter/issues/789
https://gitlab.gnome.org/GNOME/gnome-shell/merge_requests/810

js/ui/screenshot.js

index c50c4a3639d2b5f493ff5d22b906d238b9460a80..11f8afa445f92d5245251aab5e683403cfff96da 100644 (file)
@@ -86,6 +86,9 @@ var ScreenshotService = class {
     }
 
     _createStream(filename) {
+        if (filename == '')
+            return [Gio.MemoryOutputStream.new_resizable(), null];
+
         if (GLib.path_is_absolute(filename)) {
             try {
                 let file = Gio.File.new_for_path(filename);
@@ -123,7 +126,15 @@ var ScreenshotService = class {
 
         stream.close(null);
 
-        let filenameUsed = file.get_path();
+        let filenameUsed = '';
+        if (file) {
+            filenameUsed = file.get_path();
+        } else {
+            let bytes = stream.steal_as_bytes();
+            let clipboard = St.Clipboard.get_default();
+            clipboard.set_content(St.ClipboardType.CLIPBOARD, 'image/png', bytes);
+        }
+
         let retval = GLib.Variant.new('(bs)', [result, filenameUsed]);
         invocation.return_value(retval);
     }